package com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.sap.constant.ConsignmentOrderDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.ConsignmentOrder.ConsignmentOrderDTO;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: qiaojiange
 * @create: 2022/01/23
 * @Description 交货主单解析器
 */
@Component
public class ConsignmentOrderDataParse extends DataParser {

    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的标准字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("outerDeliveryOrderId", ConsignmentOrderDiffStandardFieldDict.SAP_DELIVERY_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("outerSalesOrderId", ConsignmentOrderDiffStandardFieldDict.SAP_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("salesOrderId", ConsignmentOrderDiffStandardFieldDict.OTS_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("outerStoOrderId", ConsignmentOrderDiffStandardFieldDict.SAP_STO_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("salesOrgId", ConsignmentOrderDiffStandardFieldDict.SALES_ORG_ID.getFieldCode());
        dataBaseFiledMapping.put("stoOrderId", ConsignmentOrderDiffStandardFieldDict.OTS_STO_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("deliveryDate", ConsignmentOrderDiffStandardFieldDict.DELIVERY_DATE.getFieldCode());
    }

    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof ConsignmentOrderDTO) {
            ConsignmentOrderDTO consignmentOrderDTO = (ConsignmentOrderDTO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, consignmentOrderDTO, consignmentOrderDTO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "ConsignmentOrderDTO";
    }
}
